home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch3 / Relative.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-04-01  |  3.2 KB  |  117 lines

  1. VERSION 5.00
  2. Begin VB.Form RelativeForm 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "Relative"
  5.    ClientHeight    =   3150
  6.    ClientLeft      =   1950
  7.    ClientTop       =   1620
  8.    ClientWidth     =   5175
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   210
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   345
  14.    Begin VB.PictureBox RelativePict 
  15.       AutoRedraw      =   -1  'True
  16.       Height          =   2700
  17.       Left            =   2640
  18.       ScaleHeight     =   2640
  19.       ScaleWidth      =   2355
  20.       TabIndex        =   1
  21.       Top             =   120
  22.       Width           =   2415
  23.    End
  24.    Begin VB.PictureBox RGBPict 
  25.       AutoRedraw      =   -1  'True
  26.       Height          =   2700
  27.       Left            =   120
  28.       ScaleHeight     =   2640
  29.       ScaleWidth      =   2355
  30.       TabIndex        =   0
  31.       Top             =   120
  32.       Width           =   2415
  33.    End
  34.    Begin VB.Label Label1 
  35.       Alignment       =   2  'Center
  36.       Caption         =   "Palette Relative RGB"
  37.       Height          =   255
  38.       Index           =   1
  39.       Left            =   2640
  40.       TabIndex        =   3
  41.       Top             =   2880
  42.       Width           =   2415
  43.    End
  44.    Begin VB.Label Label1 
  45.       Alignment       =   2  'Center
  46.       Caption         =   "RGB"
  47.       Height          =   255
  48.       Index           =   0
  49.       Left            =   120
  50.       TabIndex        =   2
  51.       Top             =   2880
  52.       Width           =   2415
  53.    End
  54. Attribute VB_Name = "RelativeForm"
  55. Attribute VB_GlobalNameSpace = False
  56. Attribute VB_Creatable = False
  57. Attribute VB_PredeclaredId = True
  58. Attribute VB_Exposed = False
  59. Option Explicit
  60. Private Const CLOSEST_IN_PALETTE = &H2000000
  61. ' Fill picture boxes with shades of color.
  62. Sub FillPictures()
  63. Const NUM_COLS = 16
  64. Const ROWS_PER_COLOR = 4
  65. Const NUM_ROWS = ROWS_PER_COLOR * 3
  66. Const NUM_BOXES = ROWS_PER_COLOR * NUM_COLS
  67. Dim dx As Single
  68. Dim dy As Single
  69. Dim x As Single
  70. Dim y As Single
  71. Dim clr As Integer
  72. Dim dr As Integer
  73. Dim dg As Integer
  74. Dim db As Integer
  75. Dim i As Integer
  76. Dim j As Integer
  77. Dim r As Integer
  78. Dim g As Integer
  79. Dim b As Integer
  80.     dx = RGBPict.ScaleWidth / NUM_COLS
  81.     dy = RGBPict.ScaleHeight / NUM_ROWS
  82.     For clr = 1 To 3
  83.         dr = 0
  84.         dg = 0
  85.         db = 0
  86.         Select Case clr
  87.             Case 1  ' Shades of red.
  88.                 dr = 255 / NUM_BOXES
  89.             Case 2  ' Shades of green.
  90.                 dg = 255 / NUM_BOXES
  91.             Case 3  ' Shades of blue.
  92.                 db = 255 / NUM_BOXES
  93.         End Select
  94.         
  95.         r = 0
  96.         g = 0
  97.         b = 0
  98.         For i = 1 To ROWS_PER_COLOR
  99.             x = 0
  100.             For j = 1 To NUM_COLS
  101.                 RGBPict.Line (x, y)-Step(dx, dy), _
  102.                     RGB(r, g, b), BF
  103.                 RelativePict.Line (x, y)-Step(dx, dy), _
  104.                     RGB(r, g, b) + CLOSEST_IN_PALETTE, BF
  105.                 r = r + dr
  106.                 g = g + dg
  107.                 b = b + db
  108.                 x = x + dx
  109.             Next j
  110.             y = y + dy
  111.         Next i
  112.     Next clr
  113. End Sub
  114. Private Sub Form_Load()
  115.     FillPictures
  116. End Sub
  117.